﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqliteDataAccess;
using SqliteDataAccess.SqliteDataManagerTableAdapters;
using Common;

namespace Business
{
    public class ProfilBusiness : BaseBusiness
    {
        public override int Load()
        {
            return new ProfilSekolahTableAdapter().Fill(LppbopSqlite.ProfilSekolah);
        }

        public SqliteDataManager.ProfilSekolahRow GetProfil()
        {
            try
            {
                SqliteDataManager.ProfilSekolahDataTable dt = new ProfilSekolahTableAdapter().GetData();
                if (dt.Count == 0)
                    return dt.NewProfilSekolahRow();
                else return dt[0];
            }
            catch (Exception e)
            {
                Logger.Log(e.Message + " - " + e.StackTrace);
                throw;
            }
        }

        public override int Save()
        {
            return new ProfilSekolahTableAdapter().Update(LppbopSqlite.ProfilSekolah);
        }

        public void Save(SqliteDataManager.ProfilSekolahRow profil)
        {
            ProfilSekolahTableAdapter ta = new ProfilSekolahTableAdapter();
            if (profil.IsNull("id") || profil.id == -1)
                ta.Insert(profil.yayasan, profil.ketua_yayasan, profil.sekolah, profil.kepala_sekolah, profil.bendahara_sekolah);
            else
                ta.Update(profil);
        }
    }
}
